<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>积分管理 - 学生知识管理系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #333;
        }

        .navbar {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            padding: 1rem 0;
            box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .nav-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 2rem;
        }

        .logo {
            font-size: 1.5rem;
            font-weight: bold;
            color: #667eea;
            text-decoration: none;
        }

        .nav-links {
            display: flex;
            list-style: none;
            gap: 2rem;
        }

        .nav-links a {
            text-decoration: none;
            color: #333;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .nav-links a:hover {
            color: #667eea;
        }

        .container {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 2rem;
            display: flex;
            gap: 2rem;
        }

        .sidebar {
            width: 250px;
            background: white;
            border-radius: 15px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            height: fit-content;
        }

        .profile-avatar {
            text-align: center;
            margin-bottom: 2rem;
        }

        .avatar {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            font-weight: bold;
            margin: 0 auto 1rem;
        }

        .sidebar-menu {
            list-style: none;
        }

        .sidebar-menu li {
            margin-bottom: 0.5rem;
        }

        .sidebar-menu a {
            display: block;
            padding: 0.75rem 1rem;
            text-decoration: none;
            color: #666;
            border-radius: 8px;
            transition: all 0.3s ease;
        }

        .sidebar-menu a:hover,
        .sidebar-menu a.active {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
        }

        .main-content {
            flex: 1;
            background: white;
            border-radius: 15px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }

        .page-header {
            margin-bottom: 2rem;
        }

        .page-title {
            font-size: 2rem;
            color: #333;
            margin-bottom: 0.5rem;
        }

        .page-subtitle {
            color: #666;
            font-size: 1.1rem;
        }

        .points-overview {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
            margin-bottom: 3rem;
        }

        .points-card {
            background: linear-gradient(135deg, #667eea, #764ba2);
            color: white;
            padding: 2rem;
            border-radius: 15px;
            text-align: center;
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
        }

        .points-number {
            font-size: 3rem;
            font-weight: bold;
            margin-bottom: 0.5rem;
        }

        .points-label {
            font-size: 1.1rem;
            opacity: 0.9;
        }

        .points-history {
            background: #f8f9fa;
            border-radius: 15px;
            padding: 2rem;
        }

        .history-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
        }

        .history-title {
            font-size: 1.5rem;
            color: #333;
        }

        .filter-buttons {
            display: flex;
            gap: 0.5rem;
        }

        .filter-btn {
            padding: 0.5rem 1rem;
            border: 1px solid #ddd;
            background: white;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 0.9rem;
        }

        .filter-btn.active,
        .filter-btn:hover {
            background: #667eea;
            color: white;
            border-color: #667eea;
        }

        .points-list {
            list-style: none;
        }

        .points-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem;
            border-bottom: 1px solid #eee;
            transition: background 0.3s ease;
        }

        .points-item:hover {
            background: rgba(102, 126, 234, 0.05);
        }

        .points-item:last-child {
            border-bottom: none;
        }

        .item-info {
            flex: 1;
        }

        .item-description {
            font-weight: 500;
            color: #333;
            margin-bottom: 0.25rem;
        }

        .item-time {
            font-size: 0.9rem;
            color: #666;
        }

        .item-points {
            font-size: 1.2rem;
            font-weight: bold;
        }

        .points-positive {
            color: #28a745;
        }

        .points-negative {
            color: #dc3545;
        }

        .item-type {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 15px;
            font-size: 0.8rem;
            font-weight: 500;
            margin-left: 1rem;
        }

        .type-article {
            background: #e3f2fd;
            color: #1976d2;
        }

        .type-comment {
            background: #f3e5f5;
            color: #7b1fa2;
        }

        .type-like {
            background: #ffebee;
            color: #c62828;
        }

        .type-login {
            background: #e8f5e8;
            color: #2e7d32;
        }

        .type-system {
            background: #fff3e0;
            color: #ef6c00;
        }

        .type-admin {
            background: #fce4ec;
            color: #ad1457;
        }

        .empty-state {
            text-align: center;
            padding: 3rem;
            color: #666;
        }

        .empty-icon {
            font-size: 4rem;
            margin-bottom: 1rem;
        }

        .alert {
            padding: 1rem;
            border-radius: 8px;
            margin-bottom: 1rem;
        }

        .alert-error {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="nav-container">
            <a href="/" class="logo">📚 学生知识管理系统</a>
            <ul class="nav-links">
                <li><a href="/">🏠 首页</a></li>
                <li><a href="/articles">📝 文章</a></li>
                <li><a href="/categories">📂 分类</a></li>
                <li><a href="/profile">👤 个人中心</a></li>
                <li><a href="/logout">🚪 退出</a></li>
            </ul>
        </div>
    </nav>

    <div class="container">
        <!-- 侧边栏 -->
        <aside class="sidebar">
            <div class="profile-avatar">
                <div class="avatar" th:if="${user.avatar == null}" th:text="${user.nickname != null ? user.nickname.substring(0,1) : user.username.substring(0,1)}">U</div>
                <img th:if="${user.avatar != null}" th:src="${user.avatar}" alt="用户头像" class="avatar" style="width: 60px; height: 60px; border-radius: 50%; object-fit: cover;">
                <h3 th:text="${user.nickname != null ? user.nickname : user.username}">用户名</h3>
            </div>
            <ul class="sidebar-menu">
                <li><a href="/profile">📝 个人资料</a></li>
                <li><a href="/profile/avatar">🖼️ 头像管理</a></li>
                <li><a href="/profile/points" class="active">⭐ 积分管理</a></li>
                <li><a href="/profile/articles">📚 我的文章</a></li>
                <li><a href="/profile/favorites">❤️ 我的收藏</a></li>
                <li><a href="/profile/follows">👥 我的关注</a></li>
                <li><a href="/profile/messages">💬 消息中心</a></li>
            </ul>
        </aside>

        <!-- 主要内容 -->
        <main class="main-content">
            <div class="page-header">
                <h1 class="page-title">⭐ 积分管理</h1>
                <p class="page-subtitle">查看您的积分获得和使用记录</p>
            </div>

            <!-- 错误信息 -->
            <div th:if="${error}" class="alert alert-error">
                <span th:text="${error}"></span>
            </div>

            <!-- 积分概览 -->
            <div class="points-overview">
                <div class="points-card">
                    <div class="points-number" th:text="${user.points ?: 0}">0</div>
                    <div class="points-label">当前积分</div>
                </div>
            </div>

            <!-- 积分记录 -->
            <div class="points-history">
                <div class="history-header">
                    <h3 class="history-title">积分记录</h3>
                    <div class="filter-buttons">
                        <button class="filter-btn active" onclick="filterRecords('all')">全部</button>
                        <button class="filter-btn" onclick="filterRecords('positive')">获得</button>
                        <button class="filter-btn" onclick="filterRecords('negative')">消费</button>
                    </div>
                </div>

                <div th:if="${pointRecords != null and !pointRecords.isEmpty()}">
                    <ul class="points-list">
                        <li class="points-item" th:each="record : ${pointRecords}" 
                            th:data-type="${record.points > 0 ? 'positive' : 'negative'}">
                            <div class="item-info">
                                <div class="item-description" th:text="${record.description}">积分记录描述</div>
                                <div class="item-time" th:text="${#temporals.format(record.createdAt, 'yyyy-MM-dd HH:mm:ss')}">2024-01-01 12:00:00</div>
                            </div>
                            <div class="item-points" 
                                 th:class="${record.points > 0 ? 'points-positive' : 'points-negative'}"
                                 th:text="${record.points > 0 ? '+' + record.points : record.points}">+10</div>
                            <span class="item-type" 
                                  th:class="${'type-' + #strings.toLowerCase(record.type.name())}"
                                  th:text="${record.type.getDisplayName()}">类型</span>
                        </li>
                    </ul>
                </div>

                <div th:if="${pointRecords == null or pointRecords.isEmpty()}" class="empty-state">
                    <div class="empty-icon">📊</div>
                    <h3>暂无积分记录</h3>
                    <p>开始发布文章、评论互动来获得积分吧！</p>
                </div>
            </div>
        </main>
    </div>

    <script>
        function filterRecords(type) {
            // 移除所有按钮的active类
            document.querySelectorAll('.filter-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            
            // 添加active类到当前按钮
            event.target.classList.add('active');
            
            // 显示/隐藏记录
            const items = document.querySelectorAll('.points-item');
            items.forEach(item => {
                const itemType = item.getAttribute('data-type');
                if (type === 'all' || type === itemType) {
                    item.style.display = 'flex';
                } else {
                    item.style.display = 'none';
                }
            });
        }
    </script>
</body>
</html>